import { v4 as uuidv4 } from 'uuid'

export class NodeUtils {
    /**
     * 根据自增数生成64进制id
     * @returns 64进制id字符串
     */
    static idGenerator() {
      let qutient = new Date() - new Date("2024-05-01");
      qutient += Math.ceil(Math.random() * 1000); // 防止重複
      const chars = "ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz";
      // uuid中-换成空字符串
      return "A"+uuidv4().replace(/-/g, "")
    }
    /**
     * 创建审批人对象
     */
    static createApproveNode() {
      return {
        "nodeId": this.idGenerator(),
        "nodeName": "审批人",
        "nodeDisplay": "审批人",
        "nodeType": 2,
        "nodeFrom": "",
        "nodeToList": [],
        "directorLevel": 1,
        "countersignType":"1",// 会签类型  1-或签，2-会签
        "signType": 1,
        "noHeaderAction": 1,
        "childNode": {},
        "btnPermission": {
          "$$$component&&&": '',
        },
        "error": true,
        "property": {
          "afterSignUpWay": 1
        },
        //指定成员、指定部门负责人都是通过组织树进行选择
        "nodeApproveList": [],
        //1-指定成员，4-部门负责人，6-标签，8-申请人本人，9-申请人自选
        approvalUserType:"1",
        //approvalParams 根据approvalUserType选择的类型来，指定成员：传用户id；标签：传标签id，其他类型传空值即可
        "approvalParams": "",
      };
    }
    /**
     * 创建抄送人对象
     * @returns object
     */
    static createCopyNode() {
      return {
        "nodeId": this.idGenerator(),
        "nodeName": "表决人",
        "nodeDisplay": "表决人",
        "nodeType": 5,
        "nodeFrom": "",
        "nodeToList": [],
        "error": true,
        "ccFlag": 1,
        "childNode": {},
        "property": {},
        "nodeApproveList": [],
        "vetoUsersList": [],
        votePassProportion:50,// 表决通过比例
        allowVeto: 1,//是否允许一票否决
        vetoUsers:"",// 一票否决人
        approvalUserType:"1",
        //approvalParams 根据approvalUserType选择的类型来，指定成员：传用户id；标签：传标签id，其他类型传空值即可
        "approvalParams": "",
      };
    }
   /**
   * 创建网关对象
   * @returns object
   */
  static createGatewayNode(child) {
     return {
      nodeId: this.idGenerator(),
      nodeName: "网关",
      nodeType: 4,
      nodeFrom: "",
      nodeToList: [],
      childNode: null,
      error: true,
      property: null,
      conditionExpressionList: [
        this.createConditionNode("条件1", child, 1, 0),
        this.createConditionNode("条件2", null, 2, 1),
      ],
    };
  }
  /**
   * 创建条件对象
   * @returns object
   */
  static createConditionNode(name, childNode,priority, isDefault) {
    return {
      nodeId: this.idGenerator(),
      nodeName: name || "条件1",
      nodeDisplay: name || "条件1",
      nodeType: 3,
      nodeFrom: "",
      nodeToList: [],
      priorityLevel: priority,
      conditionList: [],
      nodeApproveList: [],
      error: true,
      childNode: childNode,
      isDefault: isDefault || 0,
    };
  }
 
  /**
   * 条件判断对象
   * @returns
   */
  static createJudgeNode() {
    return {
      "nodeId": this.idGenerator(),
      "nodeName": "申请人",
      "nodeDisplay": "申请人",
      "nodeType": 1, //
      "nodeProperty": 1,
      "nodePropertyName": null,
      "nodeFrom": "",
      "nodeFromList": [],
      "nodeToList": [
        ""
      ],
    }
  }
}

/**
 * 添模拟数据
 */
export function getMockData() {
  //NodeUtils.createNode("start", "");
  return "";
}
